package com.jinwei.qunguanjia.common.utils;

import com.jinwei.qunguanjia.common.core.domain.model.LoginUser;

public class SystemContextUtils implements AutoCloseable {

    private static ThreadLocal<LoginUser> currentUserThread = new ThreadLocal<>();

    public static LoginUser getCurrentSystemUser() {
        return currentUserThread.get();
    }

    public static void setCurrentSystemUser(LoginUser currentSystemUser) {
        currentUserThread.set(currentSystemUser);
    }

    public static String getUserId() {
        return getCurrentSystemUser().getUserId();
    }

    public static String getUserName() {
        return getCurrentSystemUser().getUserName();
    }

    public static String getToken() {
        return getCurrentSystemUser().getToken();
    }

    @Override
    public void close() {
        currentUserThread.remove();
    }
}